function loading(val){
	var $loading = $('#loading');
	if(val)
		$loading.html(val);
	$loading.css('display','block');
}

function message(type,message){
	switch(type){
		case 'ok':
		case 'info':
		case 'warning':
		case 'error':
			alert('【'+type+'】'+message);
			break;
	}
}

$(document).ready(function(){
	
	$('body').append('<div id="loading">数据加载中……</div>');
	
	// 列表删除与编辑
	$('.listTable .edit').live('click',
		function(){
			var $tr = $(this).parent().parent();
			var id = $tr.find('td:first input[type="checkbox"]').val();
			var src = site_url+'/show_form/'+id;
			var $table = $tr.parent().parent();
			var oIframe = plugor.createElement('iframe',{'width':'100%','frameBorder':'0','src':src});
			plugor.bind(oIframe,'load',function(elem){
				elem.height=elem.contentWindow.document.body.clientHeight;
				elem.contentWindow.document.getElementById('backList').onclick = function(){
					$table.show();
					$(elem).remove();
				}
			});
			$table.hide();
			$table.after(oIframe);
		}
	);
	$('.listTable .delete').live('click',
		function(){
			var $tr = $(this).parent().parent();
			var id = $tr.find('td:first input[type="checkbox"]').val();
			if(confirm('您确认要删除此条信息吗？')){
				$.post(site_url+'/delete/'+id,{},function(result){
					if(result.state)
						$tr.remove();
					message(result.state?'ok':'error',result.message);
				},'json');
			}
			return;
		}
	);
		
    // Initialise Facebox Modal window:
	$('a[rel*=modal]').facebox(); // Applies modal window to any link with attribute rel="modal"

});
  
  
  